def isPrime(x):
    if x == 1: return False
    chislo = True
    a = x - 1
    while a > 1:
        if not x % a:
            chislo = False
            break
        a -= 1
    return chislo

b = input()
r = []
for i in range(len(b)):
    for k in range(i + 1, len(b) + 1):
        x = int(b[i:k])
        if isPrime(x):
            r += [x]
print(max(r) if r else 0)